package com.moodswings.server;

import com.moodswings.server.model.Mood;
import com.moodswings.server.service.MoodService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MoodServlet extends HttpServlet {

	MoodService moodService;

	public MoodServlet() {
		moodService = new MoodService();
	}



	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		//Kupi parametre i pretvara ih iz stringa u odgovarajuce velicine

		Float longitude = Float.parseFloat(req.getParameter("longitude"));
		Float lat = Float.parseFloat(req.getParameter("lat"));
		Integer moodId = Integer.parseInt(req.getParameter("moodId"));
		String userId = req.getParameter("userId");
		Long time = Long.parseLong(req.getParameter("time"));


		//stvara mood i dodeljuje mu parametre

		Mood mood = new Mood();
		mood.setLongitude(longitude);
		mood.setLatitude(lat);
		mood.setMoodId(moodId);
		mood.setUserId(userId);
		mood.setTime(time);
		//napravio mood

		moodService.addMood(mood); //prosledjuje novostvoreni mood drugoj klasi koja ga doda u bazu podataka

		resp.getWriter().write("data accepted");

	}
}